home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EDUCORP 8
/
Educorp2Compilation.sit
/
educorp2
/
Fonts (2800)
/
2830 Display Fonts
/
Font Tools
/
FontLister
/
fontList.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-12-30
|
3KB
|
163 lines
/* Font Lister Desk Accessory. Version 1.0 Dec 30/87 */
/* by Jim Leitch Toronto CIS 70416,1532 */
#include <DeviceMgr.h>
#include <EventMgr.h>
#include <WindowMgr.h>
#include <FontMgr.h>
#define DAopen 0
#define DAcontrol 2
#define DAclose 4
typedef EventRecord **EventHandle;
Boolean already_open = false;
DCtlPtr dce;
Rect windowRect;
EventRecord myEvent;
main(p,d,n)
cntrlParam *p;
DCtlPtr d;
int n;
{ if(!d->dCtlStorage)
{ if (n == DAopen)
{ SysBeep(10);
CloseDriver(d->dCtlRefNum);
}
return (noErr);
}
dce = d;
switch (n)
{ case DAopen:
doOpen();
break;
case DAcontrol:
doControl(p, d);
break;
case DAclose:
DisposeWindow(dce->dCtlWindow);
break;
default:
break;
}
return(noErr);
}
doOpen()
{ int fNum,numFonts = 0,winBottom,winRight;
char str[32];
dce->dCtlFlags |= dNeedLock;
if (already_open)
return;
for(fNum = 0; fNum <= 512; fNum++) /* scan to determine window size */
{ GetFontName(fNum,str);
if(StringWidth(str) > 0)
numFonts++;
}
winRight = numFonts > 21 ? 500 : 260;
winBottom = numFonts > 21 ? 332 : numFonts * 12 + 76;
already_open = true;
SetRect(&windowRect,8,40,winRight,winBottom);
dce->dCtlWindow =
NewWindow(0L,&windowRect,"\pAvailable Fonts",true,16,-1L,true,0L);
((WindowPeek)dce->dCtlWindow)->windowKind = dce->dCtlRefNum;
SetPort(dce->dCtlWindow);
}
doControl(p, d)
cntrlParam *p;
DCtlPtr d;
{ Point mousePt;
char ch;
switch (p->csCode)
{ case accEvent:
myEvent = **(EventHandle)p->csParam;
SetPort(dce->dCtlWindow);
switch (myEvent.what)
{ case activateEvt:
doActivate(myEvent.message);
break;
case updateEvt:
doUpdate(myEvent.message);
break;
default:
break;
}
break;
default:
break;
}
}
doActivate(convWin)
WindowPtr convWin;
{ GrafPtr oldPort;
GetPort(&oldPort);
SetPort(convWin);
SetPort(oldPort);
}
doUpdate(convWin)
WindowPtr convWin;
{ GrafPtr oldPort;
GetPort(&oldPort);
SetPort(convWin);
BeginUpdate(convWin);
decribeFonts();
EndUpdate(convWin);
SetPort(oldPort);
}
decribeFonts()
{ int fNum,fSize,h = 2,v = 22,tab,totalFonts = 0,totalSizes = 0;
Str255 str;
TextFont(1);
TextSize(9);
for(fNum = 0; fNum <= 512; fNum++)
{ GetFontName(fNum,str);
if(StringWidth(str) > 0)
{ if(v == 22 )
{ MoveTo(h,10);
DrawString("\pNumber Name Sizes");
}
writeValue(h,v,fNum);
MoveTo(h + 33,v);
DrawString(str);
tab = h + 90;
for(fSize = 7; fSize <= 48; fSize++)
if(RealFont(fNum,fSize))
{ writeValue(tab+=15,v,fSize);
totalSizes++;
}
v += 12;
totalFonts++;
if(v > 295)
{ v = 22;
h += 250;
}
}
}
v += 11;
if(v > 295)
{ v = 26;
h += 250;
}
writeValue(h + 30,v,totalFonts);
DrawString("\p Fonts");
writeValue(h + 105,v,totalSizes);
DrawString("\p Sizes");
}
writeValue(h,v,val)
int h,v,val;
{ char strg[10];
NumToString((long)val,strg);
h = val < 10 ? h = h + 6 : h;
h = val < 100 ? h = h + 6 : h;
MoveTo(h,v);
DrawString(strg);
}